package com.cloud.feign.controller;

import com.cloud.feign.service.RoleFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yingxue.lesson.entity.SysRole;
import com.yingxue.lesson.utils.DataResult;
import com.yingxue.lesson.vo.req.RolePageReqVo;
import com.yingxue.lesson.vo.resp.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

/**
 * @author lai
 * @version 1.0
 * @date 2021/5/30 12:56
 * @description
 */
@Component
@RequestMapping("/hystrix")
public class FeignHystrixService {

    @Autowired
    private RoleFeignService roleFeignService;

//    @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    })
    @PostMapping("/api/roles")
    @ResponseBody
    public DataResult hystrixRole(@RequestBody RolePageReqVo vo){
        DataResult<PageVO<SysRole>> pageInfo = roleFeignService.pageInfo(vo);
        return pageInfo;
    }

    /**
     * 超时处理方法
     */
    public String paymentTimeOutFallbackMethod(@RequestBody RolePageReqVo vo){
        return "我是消费者80,对方支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己,o(╥﹏╥)o";
    }


}
